package cn.kgcnews.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;



public class EncodingFilter01 implements Filter {
private String encoding="";
	@Override
	public void destroy() {
		// TODO Auto-generated method stub

	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse rsp,
			FilterChain chain) throws IOException, ServletException {
		System.out.println("进入到编译锅炉器");
		req.setCharacterEncoding(encoding);
		rsp.setCharacterEncoding(encoding);
		/*HttpServletRequest re = (HttpServletRequest)req;
		System.out.println(encoding);
		HttpSession session = re.getSession();
		NewsComment co=(NewsComment)session.getAttribute("comments");
		if(co!=null){
		//判断添加的字是否有
				String a="共产党";
				String con=co.getContext();
				
				if(con.contains(a)){
				    con=con.replaceAll("共产党", "***");
				    co.setContext(con);
				    System.out.println("完成");
				}
		}*/
		chain.doFilter(req, rsp);
	}

	@Override
	public void init(FilterConfig config) throws ServletException {
		
		encoding=config.getInitParameter("encoding");
	}

}
